package LeetCode.month02.day41;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.PriorityQueue;

public class No3025 {
    public static void main(String[] args) {
        System.out.println(numberOfPairs(new int[][]{{1,3},{3,1},{1,1}}));
    }
    public static int numberOfPairs(int[][] points) {
        int n = points.length;
        int res = 0;
        Arrays.sort(points,(a,b)->a[0]-b[0]==0?a[1]-b[1]:b[0]-a[0]);
        for (int i = 0; i < n; i++) {
            for (int j = i+1; j < n; j++) {
                if(points[i][1]>points[j][1]) continue;
                int[] row = new int[]{points[i][1],points[j][1]};
                int[] column = new int[]{points[j][0],points[i][0]};
                int flag = 1;
                for (int k = i+1; k < n; k++) {
                    if(k!=j&&points[k][0]>=column[0]&&points[k][0]<=column[1]
                            &&points[k][1]>=row[0]&&points[k][1]<=row[1]) {
                        flag=0;
                        break;
                    }
                }
//                if(flag==1){
//                    System.out.println("i=" + Arrays.toString(points[i]));
//                    System.out.println("j=" + Arrays.toString(points[j]));
//
//                }
                res+=flag;
            }
        }
        return res;
    }
}
